
import { IOptions } from "@/serve";

/**
 * 设置请求域名
 * @param input 
 * @returns 
 */
export function setDomain(input: RequestInfo | URL, init?: RequestInit, domain?: string, options?: IOptions): { input: RequestInfo | URL, init?: RequestInit } {
    if (typeof input === 'string') {
        return {
            input: new Request(options?.domain || domain + input),
            init,
        }
    } else if (input instanceof URL) {
        return {
            input: new Request(options?.domain || domain + input.toString()),
            init,
        }
    } else {
        return {
            input: new Request({ ...input, url: options?.domain || domain + input.url }),
            init,
        }
    }
}